package com.app.repository.impl;

import com.app.model.main.FavoriteItem;
import com.app.repository.interfaces.FavoriteItemMapper;
import com.app.support.dao.MybatisDao;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lichaojie on 2017/7/14. It's a beautiful day.
 */
@Repository
public class FavoriteItemMapperImpl implements FavoriteItemMapper {

    final String namespace = "com.app.dao.main.FavoriteItemMapper";

    @Autowired
    private MybatisDao mybatisDao;

    @Override
    public int deleteByPrimaryKey(Long id){
        return mybatisDao.delete(namespace,".deleteByPrimaryKey",id);
    }

    @Override
    public int insert(FavoriteItem record){
        return mybatisDao.insert(namespace, ".insert", record);
    }

    @Override
    public int insertSelective(FavoriteItem record){
        return mybatisDao.insert(namespace, ".insertSelective", record);
    }

    @Override
    public FavoriteItem selectByPrimaryKey(Long id){
        return mybatisDao.get(namespace, ".selectByPrimaryKey", id);
    }

    @Override
    public int updateByPrimaryKeySelective(FavoriteItem record){
        return mybatisDao.update(namespace, ".updateByPrimaryKeySelective", record);
    }

    @Override
    public int updateByPrimaryKey(FavoriteItem record){
        return mybatisDao.update(namespace, ".updateByPrimaryKey", record);
    }

    @Override
    public List<FavoriteItem> selectByFavoritesId(long favoritesId){
        return mybatisDao.getList(namespace, ".selectByFavoritesId", favoritesId);
    }

    @Override
    public FavoriteItem selectByFavoritesIdAndObjectId(long favoritesId, long objectId){
        Map<String,Object> map = new HashMap<>();
        map.put("favoritesId",favoritesId);
        map.put("objectId",objectId);
        return mybatisDao.get(namespace, ".selectByFavoritesIdAndObjectId", map);
    }

    @Override
    public FavoriteItem selectByFavoritesIdAndObjectIdWithOutFlag(long favoritesId, long objectId){
        Map<String,Object> map = new HashMap<>();
        map.put("favoritesId",favoritesId);
        map.put("objectId",objectId);
        return mybatisDao.get(namespace, ".selectByFavoritesIdAndObjectIdWithOutFlag", map);
    }

    @Override
    public List<FavoriteItem> getListOrderedByIdASC(long favoritesId, long lastId, int number, byte type){
        Map<String,Object> map = new HashMap<>();
        map.put("favoritesId",favoritesId);
        map.put("lastId",lastId);
        map.put("type", type);
        return mybatisDao.getList(namespace,".getListOrderedByIdASC",map,new RowBounds(0,number));
    }

    @Override
    public List<FavoriteItem> getListOrderedByIdDESC(long favoritesId, long lastId, int number, byte type){
        Map<String,Object> map = new HashMap<>();
        map.put("favoritesId",favoritesId);
        map.put("lastId",lastId);
        map.put("type", type);
        return mybatisDao.getList(namespace,".getListOrderedByIdDESC",map,new RowBounds(0,number));
    }

}
